package com.example.borui.partpositionproject.partpisition.itemviewtype;

import java.util.IdentityHashMap;
import java.util.Map;

/**
 * Created by borui on 2017/10/12.
 */
public class ItemViewTypeManager {

    private volatile static ItemViewTypeManager singleClazz;

    private Map<String, Integer> integerMap;

    /*** 分区类型结束点 ***/
    private int partEndItemType;

    public ItemViewTypeManager(){
        integerMap = new IdentityHashMap<>();
    }

    public static ItemViewTypeManager getInstance() {
        if (singleClazz == null) {
            synchronized (ItemViewTypeManager.class) {
                if (singleClazz == null) {
                    singleClazz = new ItemViewTypeManager();
                }
            }
        }
        return singleClazz;
    }

    /***
     * 这个方法 只能在构造方法中使用
     * @return
     */
    public int initItemViewType(String type){
        if(integerMap.containsKey(type)){
            return integerMap.get(type);
        }
        partEndItemType = partEndItemType + 1;

        integerMap.put(type, partEndItemType);
        return partEndItemType;
    }
}
